//
//  ShareBottomView.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/3/4.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit

class ShareBottomView: UIView {
    var leftBtn:UIButton = UIButton()
    var rightBtn:UIButton = UIButton()
    var btnBlock:((_ btnTag:Int) -> Void)?

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.leftBtn = UIButton(type: UIButton.ButtonType.custom)
        self.leftBtn.frame = FRAME_CGFloat(0, 0, SCREEN_WIDTH / 2, 54)
        self.leftBtn.setTitle("分享免费听", for: .normal)
        self.leftBtn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        self.leftBtn.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
        self.leftBtn.tag = 11
        self.addSubview(self.leftBtn)
        
        self.rightBtn = UIButton(type: UIButton.ButtonType.custom)
        self.rightBtn.frame = FRAME_CGFloat(SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, 54)
        self.rightBtn.setTitle("我的分享", for: .normal)
        self.rightBtn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        self.rightBtn.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
        self.rightBtn.tag = 12
        self.addSubview(self.rightBtn)
        
        setChooseBtn(btn: self.leftBtn)
        setNoChooseBtn(btn: self.rightBtn)
    }
    
    @objc func btnAction(btn:UIButton) {
        btnBlock?(btn.tag)
        if btn.tag == 11 {
            setChooseBtn(btn: self.leftBtn)
            setNoChooseBtn(btn: self.rightBtn)
        } else {
            setChooseBtn(btn: self.rightBtn)
            setNoChooseBtn(btn: self.leftBtn)
        }
    }
    
    func setChooseBtn(btn:UIButton) {
        btn.setTitleColor(.white, for: .normal)
        btn.backgroundColor = RGB(255, 151, 29)
    }
    
    func setNoChooseBtn(btn:UIButton) {
        btn.setTitleColor(RGB_Same(53), for: .normal)
        btn.backgroundColor = WhiteBackColor
    }

}
